package com.zprmb.udzt;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zprmb.udzt.fragment.My_Red_fragment;
import com.zprmb.udzt.fragment.PagerSlidingTabStrip;
/**
 * 我的红包
 * @author shenshao
 *
 */
public class MyHongBao extends BaseActivity implements OnClickListener{
	
	private ImageView img_back;
	private PagerSlidingTabStrip tabs;
	private ViewPager pager;
	private MyPagerAdapter adapter;
	private int currentColor = R.color.bbt_main_down;
	private TextView tv_title_context,tv_red_info;
	private RelativeLayout rl_back;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.my_hongbao);
		 BbtApplication.getInstance().addActvity(this);
		initView();
		img_back=(ImageView)findViewById(R.id.img_back);
		rl_back=(RelativeLayout)findViewById(R.id.rl_back);
		rl_back.setOnClickListener(this);
		img_back.setOnClickListener(this);
	}
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		BbtApplication.getInstance().removeActvity(this);
	}
	private void initView() {
		tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
		pager = (ViewPager) findViewById(R.id.pager);
		tv_red_info=(TextView)findViewById(R.id.tv_red_info);
		tv_red_info.setOnClickListener(this);
		adapter = new MyPagerAdapter(getSupportFragmentManager());
		pager.setOffscreenPageLimit(2);
		pager.setAdapter(adapter);
		final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources()
				.getDisplayMetrics());
		pager.setPageMargin(pageMargin);
		tabs.setViewPager(pager);
		tabs.setUnderlineHeight(0);
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
		case R.id.img_back:
			finish();
			break;
		case R.id.tv_red_info:
			Intent intent=new Intent(MyHongBao.this,V4WebViewActivity.class);
			intent.putExtra("title", "红包规则");
			intent.putExtra("url", "/h5/giftRule?app=true");
			startActivity(intent);
			break;
		case R.id.rl_back:
			finish();
			break;
		}
	}
	public class MyPagerAdapter extends FragmentPagerAdapter {

		private final String[] TITLES = {"可用","不可用"};
		

		public MyPagerAdapter(FragmentManager fm) {
			super(fm);
		}

		public CharSequence getPageTitle(int position) {
			return TITLES[position];
		}

		public int getCount() {
			return TITLES.length;
		}

		public Fragment getItem(int position) {
			return My_Red_fragment.newInstance(position, getToken(),TITLES[position]);
		}
	}
	

}
